<template>
  <div class="app-container">
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="123px">
      <el-form-item label="物资名称:" prop="wzName">
        <el-input size="mini"
                  v-model="queryParams.wzName"
                  placeholder="请输入物资名称"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属仓库:" prop="ckName">
        <el-input size="mini"
                  v-model="queryParams.ckName"
                  placeholder="请输入所属仓库"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属货架:" prop="hjName">
        <el-input size="mini"
                  v-model="queryParams.hjName"
                  placeholder="请输入所属货架"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属分层:" prop="fcName">
        <el-input size="mini"
                  v-model="queryParams.fcName"
                  placeholder="请输入所属分层"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资分类:" prop="wzFl">
        <el-input size="mini"
                  v-model="queryParams.wzFl"
                  placeholder="请输入物资分类"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资规格:" prop="wzGg">
        <el-input size="mini"
                  v-model="queryParams.wzGg"
                  placeholder="请输入物资规格"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物资专业:" prop="wzZy">
        <el-input size="mini"
                  v-model="queryParams.wzZy"
                  placeholder="请输入物资专业"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库关联状态:" prop="ckGlZt">
        <!--        <el-select size="mini" v-model="queryParams.ckGlZt" placeholder="请选择仓库关联状态" clearable>-->
        <!--          <el-option-->
        <!--            v-for="dict in dict.type.wzgl_ckglzt"-->
        <!--            :key="dict.value"-->
        <!--            :label="dict.label"-->
        <!--            :value="dict.value"-->
        <!--          />-->
        <!--        </el-select>-->
        <el-radio-group size="small" @change="handleQuery" v-model="queryParams.ckGlZt">
          <el-radio-button style="font-weight: 600" label="正常关联"></el-radio-button>
          <el-radio-button style="font-weight: 600" label="未关联仓库"></el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table @row-click="clickRow" ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="wzxxList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column show-overflow-tooltip label="物资名称" align="center" prop="wzName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link style="font-weight: 600" type="primary">{{ scope.row.wzName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="物资单位" align="center" prop="wzDw"/>
      <el-table-column show-overflow-tooltip label="所属仓库" align="center" prop="ckName"/>
      <el-table-column show-overflow-tooltip label="所属货架" align="center" prop="hjName"/>
      <el-table-column show-overflow-tooltip label="所属分层" align="center" prop="fcName"/>
      <el-table-column show-overflow-tooltip label="物资分类" align="center" prop="wzFl"/>
      <el-table-column show-overflow-tooltip label="安全库存" align="center" prop="aqKc"/>
      <el-table-column show-overflow-tooltip label="物资规格" align="center" prop="wzGg"/>
      <el-table-column show-overflow-tooltip label="物资专业" align="center" prop="wzZy"/>
      <el-table-column show-overflow-tooltip label="单价" align="center" prop="dj"/>
      <el-table-column show-overflow-tooltip label="物资备注" align="center" prop="wzBz"/>
      <el-table-column show-overflow-tooltip label="仓库关联状态" align="center" prop="ckGlZt">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wzgl_ckglzt" :value="scope.row.ckGlZt"/>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="库存" align="center" prop="kc"/>
      <el-table-column show-overflow-tooltip label="所属部门" align="center" prop="deptName"/>
    </el-table>

    <!-- 分页组件 -->
    <div class="pagination-containers" v-show="total > 0">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 物资详情 -->
    <WzXq ref="wzXq"/>
  </div>
</template>

<script>
import {selectWzList} from "@/api/wzgl/wzxx";
import WzXq from "@/views/wzgl/wzxx/components/WzXq.vue";

export default {
  name: "wzXxSyBm", //物资基本信息(所有部门)
  components: {WzXq},
  //物资基本信息
  dicts: ['wzgl_ckglzt'],
  data() {
    return {
      wzflData: [],
      selectedRow: null, // 保存当前选中的行
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物资基本信息表格数据
      wzxxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wzName: null,
        ssCk: null,
        ssHj: null,
        ssFc: null,
        wzFl: null,
        wzGg: null,
        wzZy: null,
        userId: null,
        deptId: null,
        ckName: null,
        hjName: null,
        fcName: null,
        ckGlZt: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 查看物资详情信息
    handleButtonClick(row) {
      this.$refs.wzXq.handleOpen(row);
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    //点击行 获取行
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      const table = this.$refs.table;
      const selectedRows = table.selection;

      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },
    /** 查询物资基本信息列表 */
    getList() {
      this.loading = true;
      selectWzList(this.queryParams).then(response => {
        this.wzxxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wzxxId: null,
        wzName: null,
        wzDw: null,
        ssCk: null,
        ssHj: null,
        ssFc: null,
        wzFl: null,
        aqKc: null,
        wzGg: null,
        wzZy: null,
        dj: null,
        wzBz: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        userId: null,
        deptId: null,
        kc: null,
        ckGlZt: null
      };
      this.resetForm("formDialog");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wzxxId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  }
};
</script>
